package com.qf.java2102.qihaonan.hotel.dao.impl;

import com.qf.java2102.qihaonan.hotel.dao.IDinnerTableDao;
import com.qf.java2102.qihaonan.hotel.pojo.DinnerTable;
import com.qf.java2102.qihaonan.hotel.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author qhn
 * @version 1.0
 */
public class DinnerTableDaoImpl implements IDinnerTableDao {

    private QueryRunner queryRunner = null;


    @Override
    public List<DinnerTable> findByTableStatus(Integer status) throws SQLException {
        queryRunner = new QueryRunner(JdbcUtils.getDataSource());

        String sql = "SELECT\n" +
                "  `table_id` tableId,\n" +
                "  `table_name` tableName,\n" +
                "  `table_status` tableStatus,\n" +
                "  `reservation_time` reservationTime\n" +
                "FROM\n" +
                "  `t_dinner_table`\n" +
                "WHERE `table_status` = ?";

        return queryRunner.query(JdbcUtils.getConnection(), sql, new BeanListHandler<>(DinnerTable.class), status);
    }
}
